/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BUS;

import DAO.TheLoaiDAO;
import Entity.TheLoai;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dark_Knight
 */
public class TheLoaiImpl implements TheLoaiBUS{

    private TheLoaiDAO dao;
    
    public TheLoaiImpl() {
        dao = new DAO.TheLoaiImpl();
    }
    
    public boolean add(TheLoai data) {
        if (data.getTenTheLoai().isEmpty())
            return false;
        
        return dao.add(data);
    }

    public ArrayList getAll() {
        ArrayList list = new ArrayList();
        ResultSet rs = dao.getAll();
        TheLoai data;
        try {
            while (rs.next()) {
                data = new TheLoai(rs.getInt(1), rs.getString(2), rs.getString(3));
                list.add(data);
            }
        } catch (SQLException ex) {
            Logger.getLogger(TheLoaiImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return list;
    }
    
}
